package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.core.annotation.Order;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/*
 *  @Author: huxinjie
 *  @Data: 2025/4/23 18:56
 *  @Description:
 */
@Mapper
public interface OrderMapper {
    //用户下单
    void insert(Orders orders);

    //根据订单号查询订单
    @Select("select * from orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);

    //订单分页查询
    Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);

    //根据订单id查询订单
    @Select("select * from orders where id = #{id}")
    Orders getOrdersById(Long id);

    void update(Orders orders);

    @Select("select count(id) from orders where status = #{status}")
    Integer countStatus(Integer toBeConfirmed);

    @Select("select * from orders where status = #{status} and order_time < #{orderTime}")
    List<Orders> getByStatusAndOrderTimeLT(Integer status, LocalDateTime orderTime);

    //根据动态条件统计营业额
    Double sumByMap(Map map);

    //根据动态条件来统计订单数
    Integer countByMap(Map map);

    //统计指定时间区间内的销量排名
    List<GoodsSalesDTO> getSalesTop(LocalDateTime begin,LocalDateTime end);
}
